package com.hospital.service.impl;

import com.hospital.dao.RegisterDao;
import com.hospital.entity.Register;
import com.hospital.service.intf.RegisterService;
import com.hospital.util.StringUtil;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fxy
 * @date 2022/8/30
 */
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private RegisterDao registerDao;
    @Override
    public R addregister(Register register) {
        if(registerDao.addregister(register)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(registerDao.selectCount(name),registerDao.selectPage(name,start,limit));
    }

    @Override
    public R updateflage(int uid) {
        if(registerDao.update(uid)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectlogPage(String depname, int page, int limit,int id) {
        if(StringUtil.isNotEmpty(depname)){
            depname="%"+depname+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(registerDao.selectLogPageCount(depname,id),registerDao.selectLogPage(depname,start,limit,id));

    }
}
